<template>
  <system-index @to-main-page="toMainPage">
    <bargain-situation ref="goodBargain" @to-page="toPage"></bargain-situation>
  </system-index>
</template>

<script>
  import SystemIndex from 'views/systemIndex';
  import BargainSituation from 'views/bargainSituation';

  import mpMixins from '../mpMixins';

  export default {
    mixins: [mpMixins],

    data() {
      return {
        paySuccess: false
      };
    },

    created() {
      window.toPaymentSuccess = () => {
        this.paySuccess = true;
        return window.Promise.resolve(true);
      };

      window.addEventListener('wxshow', () => {
        let paySuccess = this.paySuccess;
        if (paySuccess) {
          this.paySuccess = false;
          this.$refs['goodBargain'].resetBargainData();
        }
      });
    },

    components: {
      SystemIndex,
      BargainSituation
    }
  };

</script>
